﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Three
{
    internal class GameScene : ISceneUpdate
    {
        Map map;
        Snake snake;
        Food food;
        int timer = 0;

        public GameScene() 
        {
            map = new Map();
            snake = new Snake();
            food = new Food(snake);
        }

        public void Update()
        {
            if (timer%5000==0)
            { 
                map.Draw();
                food.Draw();

                snake.Move();
                snake.Draw();


                if (snake.CheckEnd())
                {
                    Game.ChangeScene(GAME_STATE.END);
                    snake.Reset();
                    food.RandomPos();
                }

                snake.CheckEatFood(food);
                
                timer = 0;
            }
            timer++;

            if (Console.KeyAvailable)
            {
                switch (Console.ReadKey(true).Key)
                {
                    case ConsoleKey.W:
                        snake.ChangeDir(SnakeDirection.UP);
                        break;
                    case ConsoleKey.S:
                        snake.ChangeDir(SnakeDirection.DOWN);
                        break;
                    case ConsoleKey.A:
                        snake.ChangeDir(SnakeDirection.LEFT);
                        break;
                    case ConsoleKey.D:
                        snake.ChangeDir(SnakeDirection.RIGHT);
                        break;
                }
            }

        }

    }
}
